

module.exports = class cost_dao extends require('../sql/cost_sql'){


    /**
     * 根据c_id获取缴费列表
     * @param req
     * @param resp
     * @returns {Promise<void>}
     */
    static async getCostData(req,resp){
        let query = req.query;
        let c_id = query.c_id;
        let paymoney = query.paymoney;
        let paystatus = query.paystatus;
        let pageNum = query.pageNum;
        let currPage = query.currPage;

        let data = await this.getCostDataSql(c_id,paymoney,paystatus,currPage,pageNum);
        let total = await this.getCostDataTotal(c_id,paymoney,paystatus);
        resp.send({data,total:total[0].count})
    }

    /**
     * 计费项目新增
     * @param req
     * @param resp
     * @returns {Promise<void>}
     */
    static async addCostData(req,resp){
        let body = req.body;
        let payname = body.payname;
        let paylevel = body.paylevel;
        let paynum = body.paynum;
        let paymoney = body.paymoney;
        let paystatus = body.paystatus;
        let c_id = body.c_id;
        let paycontent = body.paycontent;
        let coststatus = body.coststatus;
        let results = await this.addCostDataSql(payname,paylevel,paynum,paymoney,paystatus,c_id,paycontent,coststatus);
        resp.send(results)
    }


    /**
     * 根据id获取计费详情
     * @param req
     * @param resp
     * @returns {Promise<void>}
     */
    static async getCostDetail(req,resp){
        let query = req.query;
        let id = query.id;
        let data = await this.getCostDetailSql(id);
        resp.send(data)
    }


    /**
     * 删除计费项目
     * @param req
     * @param resp
     * @returns {Promise<void>}
     */
    static async delCostData(req,resp){
        let id = req.query.id;
        let results = await this.delCostDataSql(id);
        resp.send(results)
    }


    /**
     * 通知缴费
     * @param req
     * @param resp
     * @returns {Promise<void>}
     */
    static async updateCostData(req,resp){
        let body = req.body;
        let u_id = body.u_id;
        let c_id = body.c_id;
        let coststatus = body.coststatus;
        let paystatus = body.paystatus;
        let username = body.username;

        let results = await this.updateCostDataSql(u_id,c_id,coststatus);
        results += await this.upCostSql(c_id,paystatus,username);
        resp.send(results)

    }


    /**
     * 获取支付信息列表
     * @param req
     * @param resp
     * @returns {Promise<void>}
     */
    static async getPayMessage(req,resp){
        let query = req.query;
        let username = query.username;
        let payname = query.payname;
        let costtype = query.costtype;
        let coststatus = query.coststatus;
        let startDate = query.startDate;
        let endDate = query.endDate;
        let paymoney = query.paymoney;
        let paylevel = query.paylevel;
        let pageNum = query.pageNum;
        let currPage = query.currPage;

        let data = await this.getPayMessageSql(username,payname,costtype,coststatus,startDate,endDate,paymoney,paylevel,currPage,pageNum);
        let total = await this.getPayMessageTotal(username,payname,costtype,coststatus,startDate,endDate,paymoney,paylevel);
        resp.send({data,total:total[0].count})
    }


    /**
     * 用户支付
     * @param req
     * @param resp
     * @returns {Promise<void>}
     */
    static async updateUserPay(req,resp){
        let body = req.body;
        let u_id = body.u_id;
        let coststatus = body.coststatus;
        let costtype = body.costtype;
        let costcontent = body.costcontent;
        let results = await this.updateUserPaySql(u_id,coststatus,costtype,costcontent);
        results += await this.updateUserPayStatusSql(u_id,coststatus)
        resp.send(results)

    }
    
}